cmake_minimum_required(VERSION 3.12.0)

project(presto, LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Release)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# add_compile_options(-fPIC)

if(POLICY CMP0146)
    cmake_policy(SET CMP0146 OLD)
endif()

if(CMAKE_HOST_APPLE)
    find_package(FFTW3 REQUIRED)
    if(FFTW3_FOUND)
        # include_directories(/opt/homebrew/Cellar/fftw/3.3.10_1/include)
        # link_directories(/opt/homebrew/Cellar/fftw/3.3.10_1/lib/)
        message("fftw3 include: " ${FFTW3_INCLUDE_DIRS})
        message("fftw3 lib: " ${FFTW3_LIBRARY_DIRS})
        include_directories(${FFTW3_INCLUDE_DIRS})
        link_directories(${FFTW3_LIBRARY_DIRS})
    endif()
endif()

option(PRESTO_CUDA "Build PRESTO with CUDA support" OFF)
option(PRESTO_TEST "Build PRESTO TEST" OFF)

if(PRESTO_CUDA)
    find_package(CUDA QUIET)
    if(CUDA_FOUND)
        enable_language(CUDA)
        set(CMAKE_CUDA_ARCHITECTURES 52;70;75;86)
        set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
        set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -diag-suppress=2417 -diag-suppress=128")
        include_directories("${CUDA_INCLUDE_DIRS}")
        link_directories(${CUDA_TOOLKIT_ROOT_DIR}/lib64)
        add_definitions(-DHAVE_CUDA)
        message(STATUS "cuda version: " ${CUDA_VERSION_STRING})
    endif()
endif()


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

add_subdirectory(src)
add_subdirectory(apps)

if(PRESTO_TEST)
    add_subdirectory(test)
endif()


################# install ##################

add_subdirectory(include)
add_subdirectory(scripts)

